import React from 'react';
import { KDlg, useKForm, KInput, ck_empty, loc } from 'sui';

const DlgAdm = (props) => {
    const form = useKForm(props.data);

    const ck = {
        old: (v) => ck_empty(v, loc("l_282")),
        pass: (v) => {
            if (!v) {
                return loc("l_282");
            }

            if (v.length < 5) {
                return loc("l_435");
            }

            return null;
        },
        dpass: (v) => {
            const dp = form.get("dpass");
            if (v !== dp) {
                return loc("l_434");
            }

            return null;
        }
    };

    return (
        <KDlg {...props} title={loc("l_444")} ck={ck} form={form}>
            <KInput label={loc("l_282")} name="old" form={form} type="password"/>
            <KInput label={loc("l_456")} name="pass" form={form} type="password"/>
            <KInput label={loc("l_457")} name="dpass" form={form} type="password"/>
        </KDlg>
    );
};

export {DlgAdm};
